import {
  GetMemberNotices,
  GetOrderNotices,
  SetSmsMessage,
  SetXcxMessage
} from '@/services/member/notice';
import {catchException} from '@/utils/utils';
export default {
  namespace: 'notice',

  state: {
    noticeList: {},
    orderNoticeList: {}
  },

  effects: {


      *GetMemberNotices({ payload, callback }, { call, put }) {
        const data = yield call(GetMemberNotices);
        yield catchException(function* (){
          if (data&&data.Code === 0) {
            yield put({
              type: 'saveGetMemberNotices',
              payload: data.Data,
            });
            callback && callback.success && callback.success(data);
          }else {
            callback && callback.error(data)
          }
        })        
      },
      *GetOrderNotices({ payload, callback }, { call, put }) {
        const data = yield call(GetOrderNotices);
        yield catchException(function* (){
          if (data&&data.Code === 0) {
            yield put({
              type: 'saveGetOrderNotices',
              payload: data.Data,
            });
            callback && callback.success && callback.success(data);
          }else {
            callback && callback.error(data)
          }
        })        
      },
      *SetSmsMessage({ payload, callback }, { call, put }) {
        const data = yield call(SetSmsMessage,payload);
        yield catchException(function* (){
          if (data&&data.Code === 0) {
            yield put({
              type: 'saveSetSmsMessage',
              payload: data.Data,
            });
            callback && callback.success && callback.success(data);
          }else {
            callback && callback.error(data)
          }
        })        
      },
      *SetXcxMessage({ payload, callback }, { call, put }) {
        const data = yield call(SetXcxMessage,payload);
        yield catchException(function* (){
          if (data&&data.Code === 0) {
            yield put({
              type: 'saveSetXcxMessage',
              payload: data.Data,
            });
            callback && callback.success && callback.success(data);
          }else {
            callback && callback.error(data)
          }
        })       
      },

  },

  reducers: {
      saveGetMemberNotices(state, {payload}) {
          return {
              ...state,
              noticeList: payload,
          };
      },
      saveGetOrderNotices(state, {payload}) {
        return {
            ...state,
            orderNoticeList: payload,
        };
    },
  }
}
